package me.zhulu.cglib;

import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.NoOp;

/**
 * Created with IntelliJ IDEA.
 * User: herosea
 * Date: 14-4-17
 * Time: 下午4:10
 * To change this template use File | Settings | File Templates.
 */
public class TableDAOFactory {
    private static TableDAO tDao = new TableDAO();

    public static TableDAO getInstance() {
        return tDao;
    }

    public static TableDAO getAuthInstance(AuthProxy authProxy) {
        Enhancer en = new Enhancer();

        en.setSuperclass(TableDAO.class);
        en.setCallback(authProxy);
        return (TableDAO) en.create();
    }

    public static TableDAO getAuthInstanceByFilter(AuthProxy authProxy) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(TableDAO.class);
        enhancer.setCallbacks(new Callback[]{authProxy, NoOp.INSTANCE});
        enhancer.setCallbackFilter(new AuthProxyFilter());
        return (TableDAO) enhancer.create();
    }
}
